package bb.lanxing.databinding.unit;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

public class SpeedUnit extends Unit {
    public static float LegalBritishMaxNum = 220.0f;
    public static float LegalBritishMinNum = 30.0f;
    public static float LegalMetricMaxNum = 100.0f;
    public static float LegalMetricMinNum = 15.0f;

    public SpeedUnit(String str) {
        super(str, "m");
    }

    public SpeedUnit(String str, DecimalFormat decimalFormat) {
        super(str, "m", decimalFormat);
    }

    public SpeedUnit(String str, String str2, DecimalFormat decimalFormat) {
        super(str, str2, decimalFormat);
    }

    @Override
    String convertToMetric(String str) {
        this.valueMetric = this.numberDecimalFormat.format(new BigDecimal(str).multiply(new BigDecimal("1.60934")));
        return this.valueMetric;
    }

    @Override
    String convertToBritish(String str) {
        this.valueBritish = this.numberDecimalFormat.format(new BigDecimal(str).multiply(new BigDecimal("0.621371")));
        return this.valueBritish;
    }

    @Override
    String convertToMetric(String str, int i) {
        BigDecimal scale = new BigDecimal(str).multiply(new BigDecimal("1.60934")).setScale(i, RoundingMode.HALF_UP);
        this.numberDecimalFormat.setMaximumFractionDigits(i);
        this.numberDecimalFormat.setMinimumFractionDigits(i);
        this.valueMetric = this.numberDecimalFormat.format(scale);
        return this.valueMetric;
    }

    @Override
    String convertToBritish(String str, int i) {
        BigDecimal scale = new BigDecimal(str).multiply(new BigDecimal("0.621371")).setScale(i, RoundingMode.HALF_UP);
        this.numberDecimalFormat.setMaximumFractionDigits(i);
        this.numberDecimalFormat.setMinimumFractionDigits(i);
        this.valueBritish = this.numberDecimalFormat.format(scale);
        return this.valueBritish;
    }

    @Override
    String convertToMetricSpeedMiHi2cmS(String str) {
        BigDecimal multiply = new BigDecimal(str).multiply(new BigDecimal("1.60934")).multiply(new BigDecimal("5")).divide(new BigDecimal("18"), 6, 4).multiply(new BigDecimal("100"));
        this.valueMetric = multiply.setScale(0, 4).intValue() + "";
        return this.valueMetric;
    }

    @Override
    public String getUnitString(String str) {
        return str.equals("m") ? " km/h" : str.equals("f") ? " MPH" : " ";
    }
}
